﻿// Study1015.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
// 第十章 STL和泛型设计
 
#include <iostream>
#include <vector>
#include <functional>
#include <algorithm>
using namespace std;

bool g(int x, int y)
{
	return x > y;
}

int main()
{
	int intArr[] = { 30,90,10,40,70,50,20 };
	const int N = sizeof(intArr) / sizeof(int);
	vector<int> a(intArr, intArr + N);

	auto p = find_if(a.begin(), a.end(), bind2nd(ptr_fun(g), 40));
	if (p == a.end())
	{
		cout << "no element greater than 40" << endl;

	}
	else
	{
		cout << "first element greater than 40 is:" << *p << endl;
	}

	p = find_if(a.begin(), a.end(), not1(bind2nd(greater<int>(),15)));
	if (p == a.end())
	{
		cout << "no element not greater than 15" << endl;

	}
	else
	{
		cout << "first element no greater than 15 is:" << *p << endl;
	}

	p = find_if(a.begin(), a.end(), bind2nd(not2(greater<int>()),15));
	if (p == a.end())
	{
		cout << "no element not greater than 15" << endl;

	}
	else
	{
		cout << "first element no greater than 15 is:" << *p << endl;
	}

	return 0;
	
}


